#include "include/segment.h"
.text
.code64 // Assembly generates 64 bit machine instructions
.start64:

  lgdt gdtr // Notify processor of new segment descriptor table address
  
  mov $KERNEL_DS, %ax // Kernel data segment selector init
  mov %ax, %ds
  mov %ax, %ss
  mov %ax, %es
  mov %ax, %fs
  mov %ax, %gs
  
  // %rsp(stack top pointer) initially points to the bottom of the newly created stack
  mov $task0_stack, %rsp
  
  push $main // push main address to stack, expanding high 32-bit to 1
  ret // pop up to RIP
 
.align 64
gdt: // Definition of new segment descriptor table
  .quad 0x0000000000000000 /* 0 reserved */
  .quad 0x00209a0000000000 /* 1 kernel cs */
  .quad 0x0000920000000000 /* 2 kernel ds */
  .quad 0x0000000000000000 /* 3 user32 cs */
  .quad 0x0000f20000000000 /* 4 user ds */
  .quad 0x0020fa0000000000 /* 5 user64 cs */
  .fill 128, 8, 0
gdt_end:

gdtr: // Segment descriptor table address definition, total of 10B [?]
  .word gdt_end - gdt // Low 16 bits - Table length - Starting and ending offset difference of 2B
  .quad gdt // High 32-bit - Table Address 8B

// 4KB stack
  .fill 4096, 1, 0
task0_stack: